#!/bin/bash
############################################################################
# Copyright (C) 2011 Lawrence Livermore National Security, LLC
# Produced at Lawrence Livermore National Laboratory.
# Written by Jim Garlick <garlick@llnl.gov>.
# UCRL-CODE-235119
# 
# This file is part of nfsroot, a network root file system utility.
# 
# nfsroot is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free
# Software Foundation; either version 2 of the License, or (at your option)
# any later version.
#
# nfsroot is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along
# with nfsroot; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.
############################################################################
#
# nfsroot-kdumplinks - manage kdump initrd symlinks
#
# kdump startup will try to rebuild its initrd if name doesn't exist,
# or if /etc/kdump.conf (link, not necessarily target) is newer than
# initrd, but writing to /boot isn't productive on the nfsroot client.
# Fool kdump startup by creating a symlink to our initramfs.
#
# Usage: nfsroot-kdumplnks [removing_kernel_version]
#
PATH=/sbin:/usr/sbin:/bin/:/usr/bin
prog=nfsroot-kdumplinks
kdir=/boot

if ! [ -x /usr/sbin/nfsroot-setdefault ]; then
   echo "${prog}: run me chrooted in root image on the server" >&2
   exit 1
fi
rm -f $kdir/initrd-*kdump.img

shopt -s nullglob
for file in $kdir/initramfs-*; do
   kver=$(basename $file|sed -e 's/^initramfs-//'|sed -e 's/\.img$//')
   if [ "$1" != "${kver}" ]; then
      ln -s $(basename $file) $kdir/initrd-${kver}kdump.img
   fi
done
